package com.yoomiito.app.present.cicle;

import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseActPresenter;
import com.yoomiito.app.model.cicle.CicleInfo;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.ui.fragment.my.MyCircleActivity;
import com.yoomiito.app.utils.NetworkUtils;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class MyCirclePresenter extends BaseActPresenter<MyCircleActivity> {

    public MyCirclePresenter(AppConfig appConfig) {
        super(appConfig);
    }

    public void getCircle(int page){
        if (NetworkUtils.checkNetPermission(getV())){
            getV().finishRefresh();
            return;
        }
        YmApi.getYmService()
                .getMyCircle(page)
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<CicleInfo>(handleException()) {
                    @Override
                    public void onSuccess(CicleInfo cicleInfo) {
                        getV().setData(cicleInfo);
                    }

                    @Override
                    public void onFail(ApiException error) {

                    }
                });
    }
}
